package ptij.vocoder.baseModel.closed_loop;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.Token;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// GPitch
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class GPitch extends TypedAtomicActor {

    public GPitch(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        xn = new TypedIOPort(this, "xn", true, false);
        xn.setTypeEquals(BaseType.OBJECT);

        yl = new TypedIOPort(this, "yl", true, false);
        yl.setTypeEquals(BaseType.OBJECT);

        gain = new TypedIOPort(this, "gain", false, true);
        gain.setTypeEquals(BaseType.OBJECT);
        
        txdtx_ctrl = new TypedIOPort(this, "txdtx_ctrl", true, false);
        txdtx_ctrl.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort xn;
    public TypedIOPort yl;
    public TypedIOPort txdtx_ctrl;

    // Output Ports
    public TypedIOPort gain;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) txdtx_ctrl.get(0);
        Short txdtx = (Short) obj.getValue();
        if((txdtx.shortValue() & Cnst.TX_SP_FLAG) != 0) {
            obj = (ObjectToken) xn.get(0);
            Short [] arg1 = (Short []) obj.getValue();

            obj = (ObjectToken) yl.get(0);
            Short [] arg2 = (Short []) obj.getValue();

            Short res = _g_pitch(arg1, arg2);
            gain.broadcast(new ObjectToken(res));
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private Short _g_pitch(Short [] xn, Short [] yl) {

        return new Short((short)0);
    }
    
    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

}
